#!/usr/bin/env python
# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

import dbus
import dbus.service

from swindle import entity


class Network(entity.Entity):
  _I_NETWORK = 'org.chromium.flimflam.Network'

  def __init__(self, bus, dev, name):
    entity.Entity.__init__(self, bus, dev.path() + '/' + name)
    self.log('create')
    self._dev = dev
    self._name = name
    self._connected = False
    self._strength = 100

  def die(self):
    self.remove_from_connection()

  @dbus.service.method(_I_NETWORK, in_signature='', out_signature='a{sv}')
  def GetProperties(self):
    self.log('GetProperties')
    r = {}
    r['Device'] = self._dev.path()
    r['Name'] = dbus.String(self._name, variant_level=1)
    r['Connected'] = dbus.Boolean(self._connected, variant_level=1)
    r['Strength'] = dbus.Byte(self._strength, variant_level=1)
    return r

  @dbus.service.signal(_I_NETWORK, signature='sv')
  def PropertyChanged(self, key, val):
    self.log('PropertyChanged %s %s', key, val)
